import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** RPC请求端枚举 */
export enum RpcRequestSideEnum {
  /** 服务端 */
  Server = 1,
  /** 客户端 */
  Client = 2,
}

/** RPC请求端实体 */
export class RpcRequestSideEntity {
  /** 访问类型 */
  RequestSide: RpcRequestSideEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(requestSide: RpcRequestSideEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.RequestSide = requestSide;
    this.Color = color;
    switch (requestSide) {
      case RpcRequestSideEnum.Server:
        // this.Display = '服务端';
        this.Display = t('iot.enum.rpcRequestSide.server');
        this.Color = this.Color ? this.Color : '#228B22';
        break;
      case RpcRequestSideEnum.Client:
        // this.Display = '客户端';
        this.Display = t('iot.enum.rpcRequestSide.client');
        this.Color = this.Color ? this.Color : '#1E90FF';
        break;
    }
  }
}

//#region 获取RPC请求端枚举架构
/**
 * 获取RPC请求端枚举架构
 */
export function getRpcRequestSideEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: RpcRequestSideEntity[] = [
    new RpcRequestSideEntity(RpcRequestSideEnum.Server),
    new RpcRequestSideEntity(RpcRequestSideEnum.Client),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.RequestSide as number,
      label: item.Display,
      value: item.RequestSide as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
